package com.wwwc.index.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.SQLException;

import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;

import com.wwwc.util.web.*;
import com.wwwc.index.ejb.category.*;

public class SignInOffServlet extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response) {
	
	try {
	    response.setContentType("text/html");

	    String user_ip       = request.getRemoteAddr();
	    HttpSession session  = request.getSession(true);
	    PrintWriter out      = response.getWriter();
	    String call_path     = request.getContextPath()+request.getServletPath();
	   
	    String lid = (String)session.getAttribute("lid");
	    if(lid == null) {
		lid = "en";
	    }

	    ResourceBundle CategoryMessage = (ResourceBundle)session.getAttribute("CategoryMessage_"+lid);
	    if (CategoryMessage == null) {
		CategoryMessage = ResourceBundle.getBundle("Category_"+lid);
		session.setAttribute("CategoryMessage_"+lid, CategoryMessage);
	    }

	    Hashtable user_info = (Hashtable)session.getAttribute("user_info");

	    out.println("<TABLE width=100% align=center style='border-bottom:1px solid; font-size: 10pt'>");
	    if(user_info == null) {
		out.println("<TR>");
		out.println("<TD align=center><A href="+call_path+"?iid=sign_in style='text-decoration: none;'>");
		out.println(CategoryMessage.getString("Sign-In")+"</A>");
		out.println("</TD>");
		out.println("<TD align=center><A href="+call_path+"?iid=sign_join style='text-decoration: none;'>");
		out.println(CategoryMessage.getString("Join-Us")+"</A>");
		out.println("</TD>");
		out.println("</TR>");
	    }
	    else {
		out.println("<TR>");
		out.println("<TD align=center>Welcome:"+user_info.get("user_name")+"</TD>");
		out.println("<TD align=center><A href="+call_path+"?iid=sign_off style='text-decoration: none;'>");
		out.println(CategoryMessage.getString("Sign-Off")+"</A></TD>");
		out.println("</TR>");
	    }
	    out.println("</TABLE>");
	}
	catch (Exception e) {
	    System.out.println("SignInOffServlet:Exception:"+e);
	}
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws IOException, ServletException 
    {
	doPost(request, response);
    }
}








